package com.tanhua;

import com.tanhua.api.MovementsService;
import com.tanhua.api.UserInfoService;
import com.tanhua.api.UserService;
import com.tanhua.autoconfig.tmplate.AipTemplate;
import com.tanhua.autoconfig.tmplate.HuanXinTemplate;
import com.tanhua.autoconfig.tmplate.OssTemplate;

import com.tanhua.sso.pojo.Movement;
import com.tanhua.sso.pojo.User;
import com.tanhua.sso.pojo.UserInfo;
import com.tanhua.util.Constants;
import org.apache.dubbo.config.annotation.DubboReference;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
public class Demo {
    @Autowired
    private OssTemplate ossTemplate;

    @DubboReference
    private UserInfoService userInfoService;

    @DubboReference
    private UserService userService;

    @Test
    public void testTemplateUpload() throws FileNotFoundException {
        String path = "C:\\Users\\Hasee\\Desktop\\TB1JDevzrj1gK0jSZFOXXc7GpXa-764-1146.jpg";
        FileInputStream inputStream = new FileInputStream(new File(path));
        String imageUrl = ossTemplate.upload(path, inputStream);
        System.out.println(imageUrl);
    }

    @DubboReference
    private MovementsService movementApi;

    @Autowired
    private HuanXinTemplate huanXinTemplate;

    @Test
    public void register() {
        for (int i = 1; i < 106; i++) {

            User user = userService.findById(Long.valueOf(i));
            if(user != null) {
                Boolean create = huanXinTemplate.createUser("hx" + user.getId(), Constants.INIT_PASSWORD);
                if (create){
                    user.setHxUser("hx" + user.getId());
                    user.setHxPassword(Constants.INIT_PASSWORD);
                    userService.update(user);
                }
            }
        }
    }

    @Test
    public void m2(){
        huanXinTemplate.createUser("hx" + 106, Constants.INIT_PASSWORD);
    }
}
